/**
 * @author wangxiaowei
 * 组织部发文列表
 */
var sort = null;
var grid = null;
var biaoti = '发文管理';
function initzuzhibufawenlist(){
var state = Ext.get('state').getValue(); 
if(state==1){
	biaoti = '行政发文管理';
}else if(state==2){
	biaoti = '行政期刊管理';
}else if(state==3){
	biaoti = '党委期刊管理';
}
		 Ext.BLANK_IMAGE_URL=Ext.get('basePath').getValue()+"ajaxFramework/ext-2.1/resources/images/default/s.gif";

Ext.menu.RangeMenu.prototype.icons = {
	  gt: './ajaxFramework/ext-2.1/img/greater_then.png', 
	  lt: './ajaxFramework/ext-2.1/img/less_then.png',
	  eq: './ajaxFramework/ext-2.1/img/equals.png'
	};
Ext.grid.filter.StringFilter.prototype.icon = './ajaxFramework/ext-2.1/img/find.png';

var colModel = new Ext.grid.ColumnModel([
		{header:'发文号',dataIndex:'wenhao',width: 35},
		{header:'主送机关',dataIndex:'zhusong',menuDisabled : true},
		{header:'标题',dataIndex:'zhaiyao'},		
		{header:'操作',dataIndex:'operate',menuDisabled : true},
		{header:'dutyId',dataIndex:'dutyId',hidden:true}
	]);
	
var filters = new Ext.grid.GridFilters({
		 cleanParams: function(p) {  // 清除参数的方法，要保留PagingToolbar分页用的两个参数
		   //var regex = new RegExp("^" + this.paramPrefix + "\[[0-9]+\]");
		   for(var key in p) {
		      if( key != 'start' && key != 'limit' )
		   //if(regex.test(key)) {
		    delete p[key];
		            //}
		               }
          },
	     buildQuery: function(filters) {	
		  // filters 就是getFilterData返回的值, 代码中push入去的对象
		  var p = {};
		  for(var i=0, len=filters.length; i<len; i++) {
		      var f = filters[i];
		      
		      // 取得在GridFilters中定义的filters中的一个filter
		      var filter = this.getFilter( f.field );
		      // 取得传递到server的参数名称
		      var name = (filter.paramName ? filter.paramName : filter.dataIndex);
		      var value = (filter.paramValue ? filter.paramValue : f.data['value']);
		      
		      if( value != '' ) p[ name ] = value;
		  }
		  return p;
		   },	
		  filters:[
		 	{type: 'string',  dataIndex: 'zhaiyao'},
		 	{type: 'string',  dataIndex: 'wenhao'}
	]}); 
		
	var url = Ext.get('url').getValue();
	sort = new Ext.data.JsonStore({
		url:url,
		fields:['zhaiyao','zhusong','chaosong','fujian','operate','state','wenhao'],
		root:'root',
		totalProperty:'totalProperty'
	});
	var bbar = new Ext.PagingToolbar({
		pageSize:23,
		store:sort,
		displayInfo:true,
		plugins: filters,
		emptyMsg:'没有记录'
	});
	
	 grid = new Ext.grid.GridPanel({
		title:biaoti,
		tbar:[{
			 	text: '拟稿',
                iconCls: 'silk-add',
              	handler:function(){
             		window.location.href=Ext.get('basePath').getValue()+'tjsinfo/tjsoa/xingzhengfawen/nigaofrom.do'+ "?state="+state;
             	}
			},{
				 text: '直接发文',
	             iconCls: 'silk-add',
	             handler:function(){
	             	window.location.href=Ext.get('basePath').getValue()+'tjsinfo/tjsoa/xingzhengzhijiefawen/nigaofrom.do?state='+state;
	             }
		}],
		cm:colModel,
		renderTo:'topic-grid',
		store:sort,
		loadMask:true,
		autoHeight:true,
		plugins: filters,
		bbar:bbar,
		viewConfig:{
			forceFit:true,
			getRowClass:function(record,rowIndex,p,ds){
				if(record.get('state') == '是')
				{
					
					return 'red-row';
				}
				else if(record.get('state') == '中止')
				{
					
					return 'yellow-row';
				}
				else if(record.get('state') == '归档')
				{
					
					return 'blue-row';
				}
			}
		}
	});
	sort.load({params:{start:parseInt(Ext.get('xingzhengfaadminliststart').getValue()), limit:23}});	
}

/**
	 * 中止一个流程
	 * @param {} id 流程ID
	 */
	function suspend(id){
		 Ext.MessageBox.show({
           title:'消息',
           msg: '是否执行此操作?',
           buttons: Ext.MessageBox.YESNO,
           fn: function(btn){
           	  if(btn == 'yes'){
           	  	    var url = Ext.get('urlend').getValue();
					Ext.Ajax.request({
						url:url,
						params:{
							flowid:id
						},
						success:function(response, options){
							    var responseArray = Ext.util.JSON.decode(response.responseText);                                              
			                     if(responseArray.success==true){
			                        Ext.Msg.alert('信息','操作成功！',function(){
			                        	sort.reload({callback :function(){
			                        		grid.getView().refresh();	
			                        	}});										
			                        });			                     
			                     }
			                    else{
			                    	Ext.Msg.alert('信息','操作失败！');     
			                    } 
						}
					});
           	  }	
           },
           icon: Ext.MessageBox.QUESTION
       });
		
					
	}

	
/**
	 * 完结一个流程
	 * @param {} id 流程ID
	 */
	function end(id){
		 Ext.MessageBox.show({
           title:'消息',
           msg: '是否执行此操作?',
           buttons: Ext.MessageBox.YESNO,
           fn: function(btn){
           	  if(btn == 'yes'){
           	  	    var url = Ext.get('end').getValue();
					Ext.Ajax.request({
						url:url,
						params:{
							flowid:id
						},
						success:function(response, options){
							    var responseArray = Ext.util.JSON.decode(response.responseText);                                              
			                     if(responseArray.success==true){
			                        Ext.Msg.alert('信息','操作成功！',function(){
			                        	sort.reload({callback :function(){
			                        		grid.getView().refresh();	
			                        	}});										
			                        });			                     
			                     }
			                    else{
			                    	Ext.Msg.alert('信息','操作失败！');     
			                    } 
						}
					});
           	  }	
           },
           icon: Ext.MessageBox.QUESTION
       });
		
					
	}	
	
/**
	 * 重启一个流程
	 * @param {} id 流程ID
	 */
	function resume(id){
		 Ext.MessageBox.show({
           title:'消息',
           msg: '是否执行此操作?',
           buttons: Ext.MessageBox.YESNO,
           fn: function(btn){
           	  if(btn == 'yes'){
           	  	    var url = Ext.get('urlresume').getValue();
					Ext.Ajax.request({
						url:url,
						params:{
							flowid:id
						},
						success:function(response, options){
							    var responseArray = Ext.util.JSON.decode(response.responseText);                                              
			                     if(responseArray.success==true){
			                        Ext.Msg.alert('信息','操作成功！',function(){
			                        	sort.reload({callback :function(){
			                        		grid.getView().refresh();	
			                        	}});										
			                        });			                     
			                     }
			                    else{
			                    	Ext.Msg.alert('信息','操作失败！');     
			                    } 
						}
					});
           	  }	
           },
           icon: Ext.MessageBox.QUESTION
       });
	}



	
	